# -*- coding: utf-8 -*-
"""
@Time    : 2025/1/17 19:06 
@Author  : ZhangShenao 
@File    : chat_history.py 
@Desc    : 聊天历史
"""
from langchain_community.chat_message_histories import FileChatMessageHistory
from langchain_core.chat_history import BaseChatMessageHistory

# 使用内存保存聊天历史
mem_store = {}


def get_session_history(session_id: str) -> BaseChatMessageHistory:
    """
    获取会话历史
    :param session_id: 会话ID
    :return: 会话历史
    """

    # 从内存中获取聊天历史
    if session_id not in mem_store:
        # 使用文件保存聊天历史
        mem_store[session_id] = FileChatMessageHistory(file_path=f"./history_{session_id}.json")

    return mem_store[session_id]
